<!-- 检测详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 48rpx;" slot="content">检测详情</block>
		</cu-custom>
		<view class="content">
			<ul>
				<li>
					<text>任务名称：{{taskName}}</text>
				</li>
				<li>
					<text>检查人员：{{executorName}}</text>
				</li>
				<li>
					<text>业主名称：{{enterpriseName}}</text>
				</li>
				<li>
					<text>检测企业：{{examineName}}</text>
				</li>
				<li>
					<text>任务状态：{{examineStatus}}</text>
				</li>
			</ul>
		</view>

		<view v-for="(item,index) in tree" :key="index">
			<view class="zj" @click="close(index)">
				<view>{{item.name}}：已完成 <text class="title_big">{{item.doneNum}}</text> 个 / 需要完成 <text
						class="title_big">{{item.totalNum}}</text> 个</view>
				<uni-icons @click="close(index)" class="close" :type="iconStyles[index]" size="16"></uni-icons>
			</view>
			<view :style="pShows[index]? '' : 'display:none;'" class="detail">
				<view v-for="(c,cindex) in tree[index].children" :key="cindex" style="display: flex;flex-direction: row;justify-content: space-between;">
					<text>{{c.name}}</text>
					<button style="width: 120rpx;padding: 0;" class="bg-system-orange shadow"
						@click="see_detail(c.taskId)">开始检测</button>
				</view>
			</view>
		</view>


		<view v-if="otype===0" class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @tap="submit">确认任务</button>
		</view>

		<view v-if="otype===1" class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @tap="submit">开始执行</button>
		</view>

		<view v-if="otype===2" class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @tap="jsjc">结束本次维保任务/结束维保任务</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskName: '',
				executorName: '',
				enterpriseName: '',
				examineName: '',
				examineStatus: '',
				pShows:[],
				pShow: false,
				iconStyle: 'top',
				iconStyles:[],
				otype: 0,
				ucId: '',
				tree: [],
			}
		},
		onLoad(option) {
			this.ucId = option.ucId
			this.xq()
		},
		methods: {
			see_detail(index) {
				console.info("index:" + index)
			},
			close(index) {
				console.info("index:" +index+" "+this.pShows[index])
				this.pShows[index] = !this.pShows[index];
				this.pShow = !this.pShow;
				this.iconStyle = this.pShow ? 'bottom' : 'top'
				this.iconStyles[index] = this.pShows[index] ? 'bottom' : 'top'
			},
			xq() {
				// 封装参数
				let params = {
					"ucId": this.ucId
				}
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/getInExamineProjectTree',
					data: {
						...params
					}
				}).then(function(res) {
					that.taskName = res.data.data.task.taskName
					that.executorName = res.data.data.task.executorName
					that.enterpriseName = res.data.data.task.enterpriseName
					that.examineName = res.data.data.task.examineName
					that.examineStatus = res.data.data.task.examineStatus

					that.tree = res.data.data.tree
					
					// console.info(that.tree)
					
					for(let i =0;i<that.tree.length;i++){
						that.pShows[i] = false;
						that.iconStyles[i]='top';
					}
					 
				}).catch(function(e) {

				})
			},
			jsjc() {
				// 封装参数
				let params = {
					"ucId": this.ucId
				}
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/examine/setStartExamine',
					data: {
						...params
					}
				}).then(function(res) {
					
				}).catch(function(e) {

				})
			},
			submit() {
				if (this.submitId == "" || this.address == "") {
					uni.showToast({
						title: "数据不完整"
					})
					return;
				}
				let params = {
					"location": this.address,
					"ucId": this.submitId
				}
				// 生成报警信息
				let app = getApp()
				app.globalData.request({
					url: 'wx/firealarm/confirmFire',
					data: {
						...params
					}
				}).then(function(res) {
					let data = res.data.code
					if (data == 0) {
						uni.showToast({
							title: "报警成功"
						})
						uni.navigateBack({
							delta: 2
						});
					}

				}).catch(function(e) {})
			},
		}
	}
</script>

<style scoped>
	page {
		width: 100vw;
	}

	.content {
		margin-top: 24rpx;
		background-color: #FFFFFF;
	}

	ul li {
		list-style: none;
		margin: 0;
		padding: 0;
		margin-left: 24rpx;
		position: relative;
	}

	li text {
		font-size: 24rpx;
		color: #777777;
		line-height: 94rpx;
	}

	li::after {
		content: '';
		position: absolute;
		left: 2rpx;
		bottom: 0;
		right: 2rpx;
		height: 1px;
		background-color: #dcdcdc;
	}

	.zj {
		display: flex;
		justify-content: space-around;
		margin-top: 24rpx;
		background: #FFFFFF;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 24rpx;
		color: #333333;
	}

	.detail {
		display: flex;
		flex-direction: column;

	}

	.detail text {
		line-height: 105rpx;
		font-size: 21rpx;
	}

	.detail button {
		float: right;
		width: 140rpx;
		height: 50rpx;
		background: #FABD50;
		box-shadow: 0 4px 14px 0 rgba(250, 189, 80, 0.50);
		border-radius: 6px;
		border-radius: 6px;

		font-size: 21rpx;
		color: #FFFFFF;
		margin-bottom: 20rpx;
		position: absolute;
		right: 0;
		bottom: 10rpx;

	}

	.detail view {
		margin: 10rpx 40rpx;
		border-bottom: 1px solid #CCCCCC;
		position: relative;
	}

	.title_big {
		color: #FABD50;
		font-size: 32rpx;
		font-weight: 600;
		display: inline-block;
		padding: 0 12rpx;
	}

	.close {
		width: 80rpx;
	}

	.my-btn {
		height: 94rpx;
		margin-top: 80px;
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
		border-radius: 24px;
		ont-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
	}
</style>
